// 纯粹为了讲指示点Promise
import {BASE,ID,KEY} from '../config/index'
function $http(url,method="GET",data={}){
    return new Promise((resolve,reject)=>{
        // XMLHttpRequest
        wx.request({
            url:BASE+'/1.1/'+url,
            method,
            data,
            header:{
                'X-LC-Key':KEY,
                'X-LC-Id':ID,
                'content-type':'application/json'
            },
            success:(res)=>{
                resolve(res)
            },
            fail:(err)=>{
                reject(err)
            }
        })
    })
}

// $http(url).then()

function $get(url,data={}){
    return $http(url,'GET',data)
}
function $post(url,data={}){
    return $http(url,'POST',data)
}
export {
    $http,
    $get,
    $post
}